﻿#include "ThreeDText.h"
#include <vtkImageData.h>
#include <vtkVectorText.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkTriangleFilter.h>
#include <vtkUnicodeString.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkCamera.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkFreeTypeStringToImage.h>
#include <vtkTextProperty.h>

ThreeDText::ThreeDText(QWidget* parent)
	: QMainWindow(parent)
{
	vtkWidget = new QVTKOpenGLNativeWidget(this);
	this->resize(600, 400);
	this->setCentralWidget(vtkWidget);

	vtkNew<vtkFreeTypeStringToImage>str2Img;
	vtkNew<vtkTextProperty>textProperty;
	vtkNew<vtkImageData>imgData;
	vtkNew<vtkDataSetMapper>mapper;
	vtkNew<vtkActor>actor;
	vtkUnicodeString ustr = vtkUnicodeString::from_utf8(u8"hello 世界");

	textProperty->SetFontFamily(VTK_FONT_FILE);
	textProperty->SetFontFile("C:\\Windows\\Fonts\\simkai.ttf");
	str2Img->RenderString(textProperty, ustr, 500, imgData);
	mapper->SetInputDataObject(imgData);
	actor->SetMapper(mapper);
	actor->SetPosition(0, 0, -0.5);
	actor->SetScale(0.01);

	vtkNew<vtkRenderer>renderer;
	renderer->AddActor(actor);
	vtkWidget->renderWindow()->AddRenderer(renderer);

	renderer->ResetCamera();
	// Generate an interesting view
	renderer->ResetCamera();
	renderer->GetActiveCamera()->Azimuth(30);
	renderer->GetActiveCamera()->Elevation(30);
	renderer->GetActiveCamera()->Dolly(1.0);
	renderer->ResetCameraClippingRange();
}
